﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace AntikCompta.Data
{
    public class Journal
    {
        private Hashtable mExercices;
        public Journal(Hashtable aExercices)
        {
            mExercices = aExercices;
        }

        public ICollection Annees
        {
            get { return mExercices.Keys; }
        }

        public bool HasError
        {
            get
            {
                foreach (int annee in mExercices.Keys)
                {
                    if (!GetSynthese(annee))
                        return true;
                }
                return false;
            }
        }


        public bool GetSynthese(int aAnnee)
        {
            if (mExercices.ContainsKey(aAnnee) == false)
                return false;

            Exercice ex = (Exercice)mExercices[aAnnee];

            if (ex.CheckAchats() == false)
                return false;

            if (ex.CheckVentes() == false)
                return false;

            if (ex.CheckFrais() == false)
                return false;

            if (ex.CheckCaisse() == false)
                return false;

            return true;
        }

        public bool CheckAchats(int aAnnee)
        {
            if (mExercices.ContainsKey(aAnnee) == false)
                return false;

            Exercice ex = (Exercice)mExercices[aAnnee];

            return ex.CheckAchats();
        }

        public bool CheckVentes(int aAnnee)
        {
            if (mExercices.ContainsKey(aAnnee) == false)
                return false;

            Exercice ex = (Exercice)mExercices[aAnnee];

            return ex.CheckVentes();
        }

        public bool CheckFrais(int aAnnee)
        {
            if (mExercices.ContainsKey(aAnnee) == false)
                return false;

            Exercice ex = (Exercice)mExercices[aAnnee];

            return ex.CheckFrais();
        }

        public bool CheckCaisse(int aAnnee)
        {
            if (mExercices.ContainsKey(aAnnee) == false)
                return false;

            Exercice ex = (Exercice)mExercices[aAnnee];

            return ex.CheckCaisse();
        }

        internal List<string> ErreursAchats(int aAnnee)
        {
            if (mExercices.ContainsKey(aAnnee) == false)
                return new List<string>();

            Exercice ex = (Exercice)mExercices[aAnnee];

            return ex.ErreursAchats();
        }

        internal List<string> ErreursVentes(int aAnnee)
        {
            if (mExercices.ContainsKey(aAnnee) == false)
                return new List<string>();

            Exercice ex = (Exercice)mExercices[aAnnee];

            return ex.ErreursVentes();
        }

        internal List<string> ErreursCaisses(int aAnnee)
        {
            if (mExercices.ContainsKey(aAnnee) == false)
                return new List<string>();

            Exercice ex = (Exercice)mExercices[aAnnee];

            return ex.ErreursCaisses();
        }

        internal List<string> ErreursFrais(int aAnnee)
        {
            if (mExercices.ContainsKey(aAnnee) == false)
                return new List<string>();

            Exercice ex = (Exercice)mExercices[aAnnee];

            return ex.ErreursFrais();
        }
    }
}
